//
//  HMShopViewController.m
//  G05爱鲜蜂
//
//  Created by 曹魏 on 16/10/20.
//  Copyright © 2016年 何源. All rights reserved.
//

#import "HMPayTableView.h"
#import "PayCell.h"

@interface HMPayTableView ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) NSArray *payArray;
@property (nonatomic,strong) NSArray *payName;
@property (nonatomic,strong) NSArray *headerName;
@property (nonatomic,assign) BOOL btnName;
@end

@implementation HMPayTableView

-(NSArray *)payArray{
    if (_payArray == nil) {
        _payArray = [NSArray arrayWithObjects:@"v2_weixin",@"icon_qq",@"zhifubaoA",@"v2_dao", nil];
    }
    return _payArray;
}
-(NSArray *)payName {
    if (_payName == nil) {
        _payName = [NSArray arrayWithObjects:@"微信支付",@"QQ支付",@"支付宝",@"货到付款", nil];
    }
    return  _payName;
}

-(NSArray *)headerName{
    if (_headerName) {
        _headerName = [NSArray arrayWithObjects:@"选择支付方式",@"精选商品",@"费用明细", nil];
        
    }
    return _headerName;
}

-(instancetype)init {
    if ([super init]) {
        
        self.estimatedRowHeight = 20;
        self.rowHeight = UITableViewAutomaticDimension;
      
       
        
        UINib *nib = [UINib nibWithNibName:@"PayCell" bundle:nil];
        [self registerNib:nib forCellReuseIdentifier:@"PayCell"];
        UINib *nib1 = [UINib nibWithNibName:@"PayCell1" bundle:nil];
        [self registerNib:nib1 forCellReuseIdentifier:@"PayCell1"];
        UINib *nib2 = [UINib nibWithNibName:@"PayCell2" bundle:nil];
        [self registerNib:nib2 forCellReuseIdentifier:@"PayCell2"];
        UINib *nib3 = [UINib nibWithNibName:@"PayCell3" bundle:nil];
        [self registerNib:nib3 forCellReuseIdentifier:@"PayCell3"];
        
        self.delegate = self;
        self.dataSource = self;
    }
    
    return self;
}




#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 4;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    switch (section) {
        case 0:
            return 1;
            break;
        case 1:
            return 4;
            break;
        case 2:
            return 4;
            break;
            
        default:
            return 1;
            break;
    }
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    switch (indexPath.section ) {
        case 0:
        {
            PayCell *cell = [PayCell settingCell:tableView withIdentifier:@"PayCell" indexPath:indexPath];
            return cell;
        }
        case 1:
        {
            PayCell *cell = [PayCell settingCell:tableView withIdentifier:@"PayCell1" indexPath:indexPath];
            
            
            
            
            if (indexPath.row ==0) {
                cell.payImg.image = [UIImage imageNamed:self.payArray[indexPath.row]];
                cell.payName.text = self.payName[indexPath.row];
                cell.btn.selected = YES;
                self.btnName = cell.btn.selected;
                

            }else if(indexPath.row == 1) {
                cell.payImg.image = [UIImage imageNamed:self.payArray[indexPath.row]];
                cell.payName.text = self.payName[indexPath.row];

            }else if(indexPath.row == 2) {
                cell.payImg.image = [UIImage imageNamed:self.payArray[indexPath.row]];
                cell.payName.text = self.payName[indexPath.row];
            }else {
                cell.payImg.image = [UIImage imageNamed:self.payArray[indexPath.row]];
                cell.payName.text = self.payName[indexPath.row];

            }
            return cell;
        }
        case 2:
        {
            PayCell *cell = [PayCell settingCell:tableView withIdentifier:@"PayCell2" indexPath:indexPath];
            return cell;
        }
            
        default:
        {
            PayCell *cell = [PayCell settingCell:tableView withIdentifier:@"PayCell3" indexPath:indexPath];
            return cell;
        }
            
            
    }
    
}


-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return @"";
    }else if (section == 1) {
        return @"选择支付方式";
    }else if (section == 2) {
        return @"精选商品";
    }else {
        return @"费用明细";
    }

}


@end








